﻿package Classes.Elements{
	import flash.events.*;
	import flash.display.*;
	import flash.utils.Timer;
	
	import Classes.*;
	import Classes.Utils.*;
	import Classes.Interface.*;
	import Classes.Layers.*;
	import Classes.Elements.*;

	public class Emplacement extends Ground implements IFire{
		//炮弹所在层
		public var bulletLayer:Layer;
		//是否可指向目标
		public var pointable:Boolean;
		//旋转角速度
		protected var omega:Number;
		//是否可以开火
		public var fireable:Boolean;
		//是否正在开火
		public var firing:Boolean;
		//武器种类
		protected var weaponType:Object;
		//武器数量
		private var numWeapen:int;		
		//发射点数组
		public var aFirePoints:Array;
		
		//构造函数
		public function Emplacement(){
			super();			
			speed = 0;
			fireable = true;			
			//用弱引用的方式添加事件侦听器
			addEventListener(Event.ENTER_FRAME,onEnterFrame,false,0,true);
		}
		public function fire():void{
			
		}
		protected function getGolbalFirePoints():Array{
			var arrPoints:Array = [];
			for(var i:int = 0;i<aFirePoints.length;i++){
				var px:Number = aFirePoints[i][0];
				var py:Number = aFirePoints[i][1];
				var dis:Number = Math.sqrt(px*px + py*py);
				var sa:Number = (90 + Math.atan2(py,px) * 180/Math.PI)%360;
				var na:Number = (sa + this.rotation)/180*Math.PI;
				arrPoints[i] = [this.x + dis*Math.sin(na),this.y - dis*Math.cos(na)];					
			}
			return arrPoints;
		}
		
		override protected function onEnterFrame(e:Event):void{
			fireable = aTargets.length?true:false;
			pointable = fireable;
			if(isInRange()){
				if(moveable)
					move();
			}
		}
	}
}